﻿using Npgsql;
using Real.Datos.Interfaces;
using Real.Entidad;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using Dapper;
using DapperExtensions;

namespace Real.Datos.Repositories
{
    public interface IEntregaRepository : IRepository<Entrega>
    {
        List<Entrega> GetAllByDate(DateTime fecha);
    }

    public class EntregaRepository : IEntregaRepository
    {

        protected readonly IDbConnection _db;

        //public EntregaRepository()
        //{
        //    _db = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["REAL"].ToString()); 
        //}

        public IList<Entrega> FindAll()
        {
            throw new NotImplementedException();
        }

        public IList<Entrega> Find(System.Linq.Expressions.Expression<Func<Entrega, bool>> predicate)
        {
            throw new NotImplementedException();
        }

        public Entrega FindById(int id)
        {
            throw new NotImplementedException();
        }

        public int Add(Entrega newEntity)
        {
            throw new NotImplementedException();
        }

        public bool Remove(int id)
        {
            throw new NotImplementedException();
        }

        public int Modify(Entrega entity)
        {
            throw new NotImplementedException();
        }

        public List<Entrega> GetAllByDate(DateTime fecha)
        {
            string query = "SELECT * FROM ENTREGA LIMIT 15";

            using (IDbConnection _db = new NpgsqlConnection("Server=10.0.0.11; Database=rworld; User Id=alvarobuteler; Password=alvaro2013; Enlist=true;  POOLING=false"))
            {
                List<Entrega> datos = new List<Entrega>();
                datos = _db.Query<Entrega>(query).ToList();
                return datos;
            }
        }
    }
}
